package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.UserConsensusPageVO;
import com.sc.nft.entity.vo.ecology.AdminSmeltingImageVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.UserConsensus;
import com.sc.nft.mapper.UserConsensusMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * 用户共识度表(sc_user_consensus)数据DAO
 *
 * @author zxy
 * @since 2024-08-24 21:56:44
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class UserConsensusDao extends ServiceImpl<UserConsensusMapper, UserConsensus> {

    public UserConsensus getUserConsensus(Long userId) {
        return lambdaQuery().eq(UserConsensus::getUserId, userId).one();
    }
    public void addConsensus(Long userId, BigDecimal consensusNum) {
        UpdateWrapper<UserConsensus> wrapper = new UpdateWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.setSql("consensus_num=consensus_num+"+consensusNum);
        update(wrapper)   ;
    }

    public boolean subConsensus(Long userId, BigDecimal consensusNum) {
        UpdateWrapper<UserConsensus> wrapper = new UpdateWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.ge("consensus_num-"+consensusNum, 0);
        wrapper.setSql("consensus_num=consensus_num-"+consensusNum);
         return update(wrapper)   ;
    }


    /**
     * admin用户共识度列表
     * @param page
     * @param userTel
     * @return
     */
    public Page<UserConsensusPageVO> getUserConsensusAdminPage(Page page, String userTel){
        return baseMapper.getUserConsensusAdminPage(page,userTel);
    }
}